<template>
    <view class="historyPage bg-fff">
        <view class="houstList" v-for="(item, index) in houseList" :key="index" @click="toHouseDetail(item)">
            <view class="signTime">
                报名时间：{{item.post_time}}
            </view>
            <view class="prod">
                <product-item :product="item"></product-item>
            </view>
        </view>

        <up-empty text="暂无数据" marginTop="100" mode="list" v-if="houseList.length === 0 && loadingType === 'nomore'"></up-empty>

        <up-loadmore :status="loadingType" margin-top="30" v-if="houseList.length > 0" />
    </view>
</template>
<script>
	import { loadSignUpProducts } from '@/common/api/my';
	export default {
		data() {
			return {
				houseList: [],
				next: '',
				loadingType: 'loadmore',
			}
		},
		onPullDownRefresh() {
			this.reset()
			this.loadData()
		},
		onReachBottom(){
			this.loadData()
		},
		onLoad() {
			this.loadData()
		},
		methods: {
			reset(){
				this.houseList = [];
				this.next = "",
				this.loadingType = "loadmore"
			},
			//加载更多数据
			async loadData(){
				if(this.loadingType === 'loading' || this.loadingType === 'nomore') return;
				this.loadingType = 'loading';
				let url = this.next || '/product/mall/v6/check';
				try{
					let { status, detail } = await loadSignUpProducts(url);

					if(status !== 0){
						uni.$u.toast(detail);
						return;
					}
					let { results, next } = detail;
					this.houseList.push(...results);
					this.next = next;
					this.loadingType = next ? 'loadmore' : 'nomore';

					uni.stopPullDownRefresh();
				}catch(err){
					uni.stopPullDownRefresh();
				}
			},

			//跳转详情
			toHouseDetail(item){
				if(!item.shelve){
					uni.$u.toast('该楼盘目前不开放')
				}else {
					uni.navigateTo({
						url: `/pages/product/detail/index?productId=${item.product}&title=${item.title}`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.historyPage{
        min-height: 100vh;
        overflow: hidden;
		.houstList{
            padding: 0rpx 28rpx;
            border-bottom: 1rpx solid rgba(0,0,0,.06);
			.signTime{
				text-align: left;
				line-height: 70rpx;
			}
		}
	}
</style>
